# -*- coding: utf-8 -*-

import time

from PageClass.boe_NewIncomeStatementClass.Class_NewIncomeStatementBoe import Class_NewIncomeStatementBoe
from TestCases.common import LoginDepend
from TestCases.common._baseClass import _BaseClass
from Util import config, logger, record


class BoeSubmit(_BaseClass):

    def __init__(self, isExit=True):
        self.isExit = isExit
        self.login = LoginDepend('basHost', 'user')
        self.NewIncomeStatement = Class_NewIncomeStatementBoe(self.login.driver)

    def __exit__(self, *args):
        if super().__exit__(*args):
            if self.isExit:
                self.exit()
        else:
            self.exit()

    def exit(self):
        self.NewIncomeStatement.driver.quit()

    def submit(self, boe_data):
        # 打开业务报账
        logger.info(f"业务报账地址为：{config.urlDict.url.basHost}")  # .\Config\test\UrlConfig.yml
        # 打开收入报账单填单界面
        self.NewIncomeStatement.open_boe(boe_data.boeType)

        # 获取单号
        boeNo = self.NewIncomeStatement.getBoeNum()
        record.writeDataToRecord({'boeNo': boeNo, 'boeType': boe_data.boeType})
        # 主表区-业务类型
        self.NewIncomeStatement.input_operationType(boe_data.operationType)
        # 主表区-备注
        self.NewIncomeStatement.input_boeAbstract(boe_data.boeAbstract)
        # 主表附加区-客户  # small弹框 # 默认选第一个
        self.NewIncomeStatement.click_vendorId()
        self.NewIncomeStatement.selectValueFromSmallTable()
        # 收入明细区-订单编号
        self.NewIncomeStatement.input_orderNumber(boe_data.orderNumber)
        # 收入明细区-收入类型
        self.NewIncomeStatement.input_operationSubTypeName(boe_data.operationSubTypeName)
        # 收入明细区-利润中心  # small弹框 # 默认选第一个
        self.NewIncomeStatement.click_expenseDeptId()
        self.NewIncomeStatement.selectValueFromSmallTable()
        # 收入明细区-金额
        self.NewIncomeStatement.input_expenseAmount(boe_data.expenseAmount)
        # 拖动滚动条至最右侧
        self.NewIncomeStatement.scrollToRight()
        # 收入明细区-税额
        self.NewIncomeStatement.input_taxAmount(boe_data.taxAmount)
        # # 保存单据
        # self.NewIncomeStatement.click_boeSaveButton()
        # time.sleep(5)
        # 提交单据
        message = self.NewIncomeStatement.click_boeSubmitButton()
        return message
